package com.day24.Reflect01;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;

public class ReflectDemo02 {
    public static void main(String[] args) throws Exception{
        Class<?> c=Class.forName("com.day24.ClassLoader.Student");
        Constructor<?> con= c.getConstructor();
        Object obj=con.newInstance();
        System.out.println(obj);
        Field nameField=c.getField("name");
        nameField.setAccessible(true);
        nameField.set(obj,"林青霞");
        System.out.println(obj);
        Field ageField=c.getField("age");
        ageField.setAccessible(true);
        ageField.set(obj,30);
        System.out.println(obj);
        Field addressField=c.getDeclaredField("address");
        ageField.setAccessible(true);
        addressField.set(obj,30);
        System.out.println(obj);
        addressField = c.getField("address");
        addressField.setAccessible(true);
        addressField.set(obj,"北京");
        System.out.println(obj);
    }
}
